<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="d3.v5.min.js"></script>
  <style>
    .container {
      width: 200px;
      height: 200px;
      background: #efefef;
    }

    .bar {
      width: 30px;
      display: inline-block;
      background: greenyellow;
      /* height: 100px; */
      vertical-align: bottom;
      position: relative;
    }

    .bar span {
      position: absolute;
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- <div class="bar"></div> -->
  </div>

  <script>

    var dataset = [10, 20, 30, 40, 50];
    var container = d3.select('#app')
    container.selectAll('div')
      .data(dataset)
      .enter()
      .append('div')
      .style('margin-left', '5px')
      .attr('class', 'bar')
      .style('height', (d) => {
        return d + 'px';
      })
      .append('span')
      .text(function (d) {
        return d;
      })
      .style('left', (30 - 20) / 2 + 'px')
      .style('top', function (d) {
        if (d < 20) {
          return '-25px';
        }
      })
      .style('color', function (d) {
        if (d < 20) {
          return 'red';
        }
      })





  </script>

</body>

</html>